//SUMMARY:  This do file replicates analysis reported in "Trade as Villain" from the first convenience sample drawn from Prolific:

clear all
set more off

*Set classpath here:
cd "XXX"

use "Prolific experiment 1 replication data.dta"

//TABLE 4: Foreign economic policies vs automation framing
reg expandTrade i.treatment
outreg2 using "Output/Prolific_results1", replace tex(fra) ctitle(Expand trade) nocons bdec(3) label
reg limitAutom i.treatment
outreg2 using "Output/Prolific_results1", append tex(fra) ctitle(Limit autom.) nocons bdec(3) label

//TABLE 5: Perceptions of market fairness
*For presentational purposes, we rescale our meritocracy view question:
replace poorAreLazy = poorAreLazy / 100
// Trade makes market less fair
gen tradeMoreFair = 4 - tradeOnFair 
lab def fairLab 1 "Less fair" 2 "No effect" 3 "More fair"
lab val tradeMoreFair fairLab
reg tradeMoreFair poorAreLazy female age hhinc i.educ4cat isWhite i.treatment usaSuperior
outreg2 using "Output/fairness", replace tex(fra) ctitle(Market fairness (Trade)) nocons bdec(3) label
// So does affirmative action
gen affactMoreFair = 4 - affactOnFairness
lab val affactMoreFair fairLab
reg affactMoreFair poorAreLazy female age hhinc i.educ4cat isWhite i.treatment usaSuperior
outreg2 using "Output/fairness", append tex(fra) ctitle(Market fairness (Aff. act.)) nocons bdec(3) label
// But not automation
gen automMoreFair = 4 - automOnFairness
lab val automMoreFair fairLab
reg automMoreFair poorAreLazy female age hhinc i.educ4cat isWhite i.treatment usaSuperior
outreg2 using "Output/fairness", append tex(fra) ctitle(Market fairness (Automation)) nocons bdec(3) label

//APPENDIX RESULTS
*Define control variables:
global cov "age female i.educ4cat hhinc isWhite ib3.pid3"

//FIGURE A8:  Treatment effect, by meritocracy
reg expandTrade i.treatment##strictMeritocrat $cov
margins, dydx(treatment) at(strictMeritocrat = 1) post
est sto treat_strictMeritYes

reg expandTrade i.treatment##strictMeritocrat $cov
margins, dydx(treatment) at(strictMeritocrat = 0) post
est sto treat_strictMeritNo

coefplot (treat_strictMeritYes) (treat_strictMeritNo), drop($cov) recast(bar) barwidth(.3) bargap(10) fcolor(*.5) ciopts(recast(rcap)) citop format(%9.2f) levels(90) vertical yline(0) leg(order(1 "Meritocrats" 3 "Non-meritocrats")) ytitle(Expand trade) title("Treatment effect (by meritocracy beliefs)")
graph export "Output/TreatmentxStrictMerit.png", as(png) replace

//FIGURE A9:  Treatment effect, by meritocracy and IME
reg expandTrade i.treatment##childBetter##strictMerit $cov
margins, dydx(treatment) at(childBetter = 0 strictMeritocrat = 1) post
est sto childNoXstrictMeritYes
reg expandTrade i.treatment##childBetter##strictMerit $cov
margins, dydx(treatment) at(childBetter = 1 strictMeritocrat = 1) post
est sto childYesXstrictMeritYes
reg expandTrade i.treatment##childBetter##strictMerit $cov
margins, dydx(treatment) at(childBetter = 0 strictMeritocrat = 0) post
est sto childNoXstrictMeritNo
reg expandTrade i.treatment##childBetter##strictMerit $cov
margins, dydx(treatment) at(childBetter = 1 strictMeritocrat = 0) post
est sto childYesXstrictMeritNo
coefplot (childNoXstrictMeritYes) (childYesXstrictMeritYes) (childNoXstrictMeritNo)  (childYesXstrictMeritNo), drop(2.treatment) recast(bar) barwidth(.19) bargap(10) fcolor(*.5) ciopts(recast(rcap)) citop format(%9.2f) levels(90) vertical yline(0) leg(order(1 "Meritocrat (low IME)" 3 "Meritocrat (high IME)" 5 "Non-meritocrat (low IME)" 7 "Non-meritocrat (high IME)")) ytitle(Expand trade) title("Treatment effect (social mobility X meritocracy beliefs)")
graph export "Output/TreatmentxStrictMeritocracyxChild_future.png", as(png) replace

//TABLE A6:  FEP vs automation framing
reg expandTrade i.treatment
outreg2 using "Output/Prolific_results2", replace tex(fra) ctitle(Expand trade) nocons bdec(3) label
reg expandTrade i.treatment##strictMeritocrat $cov
outreg2 using "Output/Prolific_results2", append tex(fra) ctitle(Expand trade) nocons bdec(3) label
reg expandTrade i.treatment##childBetter##strictMerit $cov
outreg2 using "Output/Prolific_results2", append tex(fra) ctitle(Expand trade) nocons bdec(3) label

//FIGURE A10:  Controlling for nationalism
reg expandTrade i.treatment##strictMeritocrat i.nationalist $cov 
margins, dydx(treatment) at(strictMeritocrat = 1) post
est sto treat_strictMeritYes_widUSA
reg expandTrade i.treatment##strictMeritocrat i.nationalist $cov
margins, dydx(treatment) at(strictMeritocrat = 0) post
est sto treat_strictMeritNo_widUSA
coefplot (treat_strictMeritYes_widUSA) (treat_strictMeritNo_widUSA), vertical yline(0) leg(order(2 "Meritocrats" 4 "Non-meritocrats")) ytitle(Change in Pr(Expand trade)) title(Controlling for US nationalism)
graph export "Output\Treatment(control_natl).png", as(png) replace

//FIGURE A11:  Treatment x nationalism
reg expandTrade i.treatment##nationalist $cov
margins, dydx(treatment) at(nationalist = 1) post
est sto natlYes
reg expandTrade i.treatment##nationalist $cov
margins, dydx(treatment) at(nationalist = 0) post
est sto natlNo
coefplot (natlYes) (natlNo), vertical yline(0) leg(order(2 "High national superiority" 4 "Low national superiority")) ytitle(Change in Pr(Expand trade)) title(Treatment X US nationalism)
graph export "Output\TreatmentxNationalism.png", as(png) replace

//FIGURE A12:  Controlling for white identity
reg expandTrade i.treatment##strictMeritocrat whiteID $cov 
margins, dydx(treatment) at(strictMeritocrat = 1) post
est sto treat_strictMeritYes_wid
reg expandTrade i.treatment##strictMeritocrat whiteID $cov 
margins, dydx(treatment) at(strictMeritocrat = 0) post
est sto treat_strictMeritNo_wid
coefplot (treat_strictMeritYes_wid) (treat_strictMeritNo_wid), vertical yline(0) leg(order(2 "Meritocrat" 4 "Non-meritocrat")) ytitle(Change in Pr(Expand trade)) title(Controlling for white ID)
graph export "Output\Treatment(control_whiteID).png", as(png) replace

//FIGURE A13:  Treatment x white ID
reg expandTrade i.treatment##whiteID $cov
margins, dydx(treatment) at(whiteID = 1) post
est sto widYes
reg expandTrade i.treatment##whiteID $cov
margins, dydx(treatment) at(whiteID = 0) post
est sto widNo
coefplot (widYes) (widNo), vertical yline(0) leg(order(2 "White ID" 4 "Not White ID")) ytitle(Change in Pr(Expand trade)) title(Treatment X white ID)
graph export "Output\TreatmentXWhiteID.png", as(png) replace
